package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourcePosPaymentRecords;
import com.zjjk.transfer.source.mapper.SourcePosPaymentRecordsMapper;
import com.zjjk.transfer.source.service.SourcePosPaymentRecordsService;
import com.zjjk.transfer.source.param.SourcePosPaymentRecordsPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * pos机收款记录 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourcePosPaymentRecordsServiceImpl extends BaseServiceImpl<SourcePosPaymentRecordsMapper, SourcePosPaymentRecords> implements SourcePosPaymentRecordsService {

    @Autowired
    private SourcePosPaymentRecordsMapper sourcePosPaymentRecordsMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourcePosPaymentRecords(SourcePosPaymentRecords sourcePosPaymentRecords) throws Exception {
        return super.save(sourcePosPaymentRecords);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourcePosPaymentRecords(SourcePosPaymentRecords sourcePosPaymentRecords) throws Exception {
        return super.updateById(sourcePosPaymentRecords);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourcePosPaymentRecords(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourcePosPaymentRecords> getSourcePosPaymentRecordsPageList(SourcePosPaymentRecordsPageParam sourcePosPaymentRecordsPageParam) throws Exception {
        Page<SourcePosPaymentRecords> page = new PageInfo<>(sourcePosPaymentRecordsPageParam, OrderItem.desc(getLambdaColumn(SourcePosPaymentRecords::getCreateTime)));
        LambdaQueryWrapper<SourcePosPaymentRecords> wrapper = new LambdaQueryWrapper<>();
        IPage<SourcePosPaymentRecords> iPage = sourcePosPaymentRecordsMapper.selectPage(page, wrapper);
        return new Paging<SourcePosPaymentRecords>(iPage);
    }

}
